package cn.lctvu.servlet.client;

import cn.lctvu.bean.ItemNews;
import cn.lctvu.bean.News;
import cn.lctvu.service.ItemNewsService;
import cn.lctvu.service.NewsService;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ItemNewsService itemNewsService=new ItemNewsService();
        //获得新闻动态前6条
        List<ItemNews> listxwdt= itemNewsService.getNewsByItemTop(1);
        //获得实时资讯前6条
        List<ItemNews> listsszx=itemNewsService.getNewsByItemTop(2);
        //获得考试资讯前6条
        List<ItemNews> listkszx=itemNewsService.getNewsByItemTop(3);
        //获得消防工程师1前6条
        List<ItemNews> listxfgcs1=itemNewsService.getNewsByItemTop(4);
        //获得消防工程师2前6条
        List<ItemNews> listxfgcs2=itemNewsService.getNewsByItemTop(6);
        //把新闻动态放入request域对象
        request.setAttribute("listxwdt",listxwdt);
        //把实时资讯放入request域对象
        request.setAttribute("listsszx",listsszx);
        //把考试 资讯放入request域对象
        request.setAttribute("listkszx",listkszx);
        //把消防工程师1放入request域对象
        request.setAttribute("listxfgcs1",listxfgcs1);
        //把消防工程师2放入request域对象
        request.setAttribute("listxfgcs2",listxfgcs2);
        //转发到myindex.jsp
        RequestDispatcher dispatcher=request.getRequestDispatcher("/myindex.jsp");
        dispatcher.forward(request,response);
    }
}
